'''
https://leetcode.cn/problems/koko-eating-bananas/
'''
from typing import List

class Solution:
    def minEatingSpeed(self, piles: List[int], h: int) -> int:
        def get_time(speed):
            hours = 0
            for pile in piles:
                hours += (pile + speed - 1) // speed
            return hours

        l, r = 1, max(piles)
        best_speed = r
        while l < r:
            m = (r + l) // 2
            if get_time(m) <= h:
                best_speed = m
                r = m
            else:
                l = m + 1
        return best_speed
